#!/bin/sh
# 从Oracle导出的整体DDL文件，提取建表（CREATE TABLE）部分，
# 提取的CREATE TABLE语句仍然是Oracle格式，需要进一步处理

src_ddl_file=
dest_ddl_file=

usage="\
Usage:
      $(basename $0) -i src_ddl_file -o dest_ddl_file

Options:
       -i <input ddl file>
  
       -o <output ddl file>

       -h show help
"

while test $# -ne 0; do
  case $1 in
    -i) src_ddl_file=$2;shift;;

    -o) dest_ddl_file=$2;shift;;

    -h) echo "$usage";exit $?;;

    *) echo "$usage";exit $?;;
  esac
  shift
done

if test -z "$src_ddl_file";then
  echo "$usage"
  exit 1
fi

cat $src_ddl_file |awk '/create table/,/;/' > $dest_ddl_file
cnt=$(grep 'create table' $dest_ddl_file|uniq|wc -l)
echo "Extracted $cnt create tables."

